using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class LevelEntityAudioComponent : EntityAudioComponent
    {
        private new LevelPlayRealityEntity _entity;

        public override void OnCreate(TEntity entity)
        {
            base.OnCreate(entity);
            _entity = entity as LevelPlayRealityEntity;
        }

        protected override GameObject GetGameObject()
        {
            return _entity?.transform.gameObject;
        }

        protected override void OnPlayAudio()
        {
            var dynEntity = _entity.GetDynLevelEntity();
            if (dynEntity.loopAudio == 0)
            {
                return;
            }
            PlayAudio(dynEntity.loopAudio);
        }

        public override void OnPoolReset()
        {
            base.OnPoolReset();
            _entity = null;
        }
    }
}
